From 7c6e0e53a6340b8cf2cad3df826fb6add419b596 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Thu, 2 Nov 2017 15:50:15 -0500 Subject: [PATCH] More header cleanups from trees laying around. More C++-like Whitespace fixes Include guards --- cet.h | 2 + cet_util.h | 8 ++-- defs.h | 17 ++------- filterdefs.h | 12 +++++- gbser.h | 2 + grtcirc.cc | 106 +++++++++++++++++++++++---------------------------- height.h | 7 ++++ magellan.h | 8 ++++ navilink.h | 6 +-- queue.h | 3 ++ session.h | 8 ++-- xmlgeneric.h | 14 ++++++- 12 files changed, 107 insertions(+), 86 deletions(-) diff --git a/cet.h b/cet.h index 62f85b80d..cd4fe108f 100644 --- a/cet.h +++ b/cet.h @@ -22,6 +22,8 @@ #ifndef CET_H #define CET_H +#include // for size_t + #define CET_ERROR 1 #define CET_SUCCESS 0 diff --git a/cet_util.h b/cet_util.h index fb08c6c80..8c87895ad 100644 --- a/cet_util.h +++ b/cet_util.h @@ -19,14 +19,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ -#ifndef CET_UTIL_H -#define CET_UTIL_H +#ifndef CET_UTIL_H_INCLUDED_ +#define CET_UTIL_H_INCLUDED_ #if HAVE_CONFIG_H #include "config.h" #endif +#include #include "cet.h" +#include "defs.h" cet_cs_vec_t* cet_find_cs_by_name(const QString& name); void cet_register(void); @@ -67,4 +69,4 @@ void cet_convert_deinit(void); void cet_disp_character_set_names(FILE* fout); -#endif +#endif // CET_UTIL_H_INCLUDED_ diff --git a/defs.h b/defs.h index 037fee7a0..e1d6f26e8 100644 --- a/defs.h +++ b/defs.h @@ -16,8 +16,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ -#ifndef gpsbabel_defs_h_included -#define gpsbabel_defs_h_included +#ifndef DEFS_H_INCLUDED_ +#define DEFS_H_INCLUDED_ #include @@ -433,12 +433,6 @@ const global_trait* get_traits(); #define WAYPT_HAS(wpt,member) (wpt->wpt_flags.member) #define CSTRc(qstr) (qstr.toLatin1().constData()) -// Maybe the XmlGeneric string callback really shouldn't have a type -// of its own; this was a crutch during the move from char* to QString. -// It's "just" a search and replace to make it go away, but it might -// be convenient to overload some day. -typedef const QString& xg_string; - /* * This is a waypoint, as stored in the GPSR. It tries to not * cater to any specific model or protocol. Anything that needs to @@ -630,11 +624,6 @@ char* GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS); #define get_option(iarglist, argname) GET_OPTION(iarglist, argname, __FILE__, __LINE__) #endif -typedef void (*filter_init)(char const*); -typedef void (*filter_process)(void); -typedef void (*filter_deinit)(void); -typedef void (*filter_exit)(void); - typedef void (*waypt_cb)(const Waypoint*); typedef void (*route_hdr)(const route_head*); typedef void (*route_trl)(const route_head*); @@ -1174,4 +1163,4 @@ int color_to_bbggrr(const char* cname); // It's here instead of gps to avoid C/C++ linkage issues. int32_t GPS_Lookup_Datum_Index(const QString& n); -#endif /* gpsbabel_defs_h_included */ +#endif // DEFS_H_INCLUDED_ diff --git a/filterdefs.h b/filterdefs.h index 93ba2e51d..9803bed34 100644 --- a/filterdefs.h +++ b/filterdefs.h @@ -26,17 +26,25 @@ * This is our (weak) attempt to make that distinction. */ -extern queue waypt_head; #if NEWQ +#include extern QList waypt_list; +#else +#include "queue.h" +extern queue waypt_head; #endif +typedef void (*filter_init)(char const*); +typedef void (*filter_process)(void); +typedef void (*filter_deinit)(void); +typedef void (*filter_exit)(void); + typedef struct filter_vecs { filter_init f_init; filter_process f_process; filter_deinit f_deinit; filter_exit f_exit; - arglist_t* args; + struct arglist* args; } filter_vecs_t; filter_vecs_t* find_filter_vec(char* const, char**); diff --git a/gbser.h b/gbser.h index 6730be9ee..661d2c505 100644 --- a/gbser.h +++ b/gbser.h @@ -22,6 +22,8 @@ #ifndef __GBSER_H #define __GBSER_H +#include // for size_t + #define gbser_OK 0 #define gbser_NOTHING -1 #define gbser_TIMEOUT -2 diff --git a/grtcirc.cc b/grtcirc.cc index 1ccfdf99f..2f6102f35 100644 --- a/grtcirc.cc +++ b/grtcirc.cc @@ -32,15 +32,15 @@ static void crossproduct(double x1, double y1, double z1, double x2, double y2, double z2, double* xa, double* ya, double* za) { - *xa = y1*z2-y2*z1; - *ya = z1*x2-z2*x1; - *za = x1*y2-y1*x2; + *xa = y1 * z2 - y2 * z1; + *ya = z1 * x2 - z2 * x1; + *za = x1 * y2 - y1 * x2; } static double dotproduct(double x1, double y1, double z1, double x2, double y2, double z2) { - return (x1*x2+y1*y2+z1*z2); + return (x1 * x2 + y1 * y2 + z1 * z2); } /* @@ -56,8 +56,8 @@ static double dotproduct(double x1, double y1, double z1, double radtomiles(double rads) { - const double radmiles = EARTH_RAD*100.0/2.54/12.0/5280.0; - return (rads*radmiles); + const double radmiles = EARTH_RAD * 100.0 / 2.54 / 12.0 / 5280.0; + return (rads * radmiles); } double radtometers(double rads) @@ -85,15 +85,9 @@ double gcdist(double lat1, double lon1, double lat2, double lon2) res = asin(res); - if ( -#if defined isnan - /* This is a C99-ism. */ - isnan(res) || -#endif - errno == EDOM) { /* this should never happen: */ - errno = 0; /* Math argument out of domain of - function, */ - return 0; /* or value returned is not a number */ + if (isnan(res) || (errno == EDOM)) { /* this should never happen: */ + errno = 0; /* Math argument out of domain of function, */ + return 0; /* or value returned is not a number */ } return 2.0 * res; @@ -134,21 +128,20 @@ double linedistprj(double lat1, double lon1, double* prjlat, double* prjlon, double* frac) { - static double _lat1 = -9999; static double _lat2 = -9999; static double _lon1 = -9999; static double _lon2 = -9999; - static double x1,y1,z1; - static double x2,y2,z2; - static double xa,ya,za,la; + static double x1, y1, z1; + static double x2, y2, z2; + static double xa, ya, za, la; - double x3,y3,z3; - double xp,yp,zp,lp; + double x3, y3, z3; + double xp, yp, zp, lp; - double xa1,ya1,za1; - double xa2,ya2,za2; + double xa1, ya1, za1; + double xa2, ya2, za2; double d1, d2; double c1, c2; @@ -181,23 +174,23 @@ double linedistprj(double lat1, double lon1, /* polar to ECEF rectangular */ if (newpoints) { - x1 = cos(lon1)*cos(lat1); + x1 = cos(lon1) * cos(lat1); y1 = sin(lat1); - z1 = sin(lon1)*cos(lat1); - x2 = cos(lon2)*cos(lat2); + z1 = sin(lon1) * cos(lat1); + x2 = cos(lon2) * cos(lat2); y2 = sin(lat2); - z2 = sin(lon2)*cos(lat2); + z2 = sin(lon2) * cos(lat2); } - x3 = cos(lon3)*cos(lat3); + x3 = cos(lon3) * cos(lat3); y3 = sin(lat3); - z3 = sin(lon3)*cos(lat3); + z3 = sin(lon3) * cos(lat3); if (newpoints) { /* 'a' is the axis; the line that passes through the center of the earth * and is perpendicular to the great circle through point 1 and point 2 * It is computed by taking the cross product of the '1' and '2' vectors.*/ crossproduct(x1, y1, z1, x2, y2, z2, &xa, &ya, &za); - la = sqrt(xa*xa+ya*ya+za*za); + la = sqrt(xa * xa + ya * ya + za * za); if (la) { xa /= la; @@ -206,30 +199,28 @@ double linedistprj(double lat1, double lon1, } } if (la) { - /* dot is the component of the length of '3' that is along the axis. * What's left is a non-normalized vector that lies in the plane of * 1 and 2. */ - dot = dotproduct(x3,y3,z3,xa,ya,za); + dot = dotproduct(x3, y3, z3, xa, ya, za); - xp = x3-dot*xa; - yp = y3-dot*ya; - zp = z3-dot*za; + xp = x3 - dot * xa; + yp = y3 - dot * ya; + zp = z3 - dot * za; - lp = sqrt(xp*xp+yp*yp+zp*zp); + lp = sqrt(xp * xp + yp * yp + zp * zp); if (lp) { - /* After this, 'p' is normalized */ xp /= lp; yp /= lp; zp /= lp; - crossproduct(x1,y1,z1,xp,yp,zp,&xa1,&ya1,&za1); + crossproduct(x1, y1, z1, xp, yp, zp, &xa1, &ya1, &za1); d1 = dotproduct(xa1, ya1, za1, xa, ya, za); - crossproduct(xp,yp,zp,x2,y2,z2,&xa2,&ya2,&za2); + crossproduct(xp, yp, zp, x2, y2, z2, &xa2, &ya2, &za2); d2 = dotproduct(xa2, ya2, za2, xa, ya, za); if (d1 >= 0 && d2 >= 0) { @@ -248,14 +239,14 @@ double linedistprj(double lat1, double lon1, } else { *prjlon = DEG(atan2(zp, xp)); } - *frac = d1/(d1 + d2); + *frac = d1 / (d1 + d2); - return atan(fabs(dot)/lp); + return atan(fabs(dot) / lp); } /* otherwise, get the distance from the closest endpoint */ - c1 = dotproduct(x1,y1,z1,xp,yp,zp); - c2 = dotproduct(x2,y2,z2,xp,yp,zp); + c1 = dotproduct(x1, y1, z1, xp, yp, zp); + c2 = dotproduct(x2, y2, z2, xp, yp, zp); d1 = fabs(d1); d2 = fabs(d2); @@ -276,29 +267,28 @@ double linedistprj(double lat1, double lon1, } if (fabs(d1) < fabs(d2)) { - return gcdist(lat1,lon1,lat3,lon3); + return gcdist(lat1, lon1, lat3, lon3); } else { *prjlat = DEG(lat2); *prjlon = DEG(lon2); *frac = 1.0; - return gcdist(lat2,lon2,lat3,lon3); + return gcdist(lat2, lon2, lat3, lon3); } } else { /* lp is 0 when 3 is 90 degrees from the great circle */ - return M_PI/2; + return M_PI / 2; } } else { /* la is 0 when 1 and 2 are either the same point or 180 degrees apart */ - dot = dotproduct(x1,y1,z1,x2,y2,z2); + dot = dotproduct(x1, y1, z1, x2, y2, z2); if (dot >= 0) { - return gcdist(lat1,lon1,lat3,lon3); + return gcdist(lat1, lon1, lat3, lon3); } else { return 0; } } } - double linedist(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3) @@ -319,10 +309,9 @@ void linepart(double lat1, double lon1, double frac, double* reslat, double* reslon) { - - double x1,y1,z1; - double x2,y2,z2; - double xa,ya,za,la; + double x1, y1, z1; + double x2, y2, z2; + double xa, ya, za, la; double xr, yr, zr; double xx, yx, zx; @@ -342,18 +331,18 @@ void linepart(double lat1, double lon1, lon2 = RAD(lon2); /* polar to ECEF rectangular */ - x1 = cos(lon1)*cos(lat1); + x1 = cos(lon1) * cos(lat1); y1 = sin(lat1); - z1 = sin(lon1)*cos(lat1); - x2 = cos(lon2)*cos(lat2); + z1 = sin(lon1) * cos(lat1); + x2 = cos(lon2) * cos(lat2); y2 = sin(lat2); - z2 = sin(lon2)*cos(lat2); + z2 = sin(lon2) * cos(lat2); /* 'a' is the axis; the line that passes through the center of the earth * and is perpendicular to the great circle through point 1 and point 2 * It is computed by taking the cross product of the '1' and '2' vectors.*/ crossproduct(x1, y1, z1, x2, y2, z2, &xa, &ya, &za); - la = sqrt(xa*xa+ya*ya+za*za); + la = sqrt(xa * xa + ya * ya + za * za); if (la) { xa /= la; @@ -365,7 +354,6 @@ void linepart(double lat1, double lon1, if (la) { crossproduct(x1, y1, z1, xa, ya, za, &xx, &yx, &zx); - theta = atan2(dotproduct(xx,yx,zx,x2,y2,z2), dotproduct(x1,y1,z1,x2,y2,z2)); diff --git a/height.h b/height.h index 50d5793fd..fd8f397dc 100644 --- a/height.h +++ b/height.h @@ -16,7 +16,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#ifndef HEIGHT_H_INCLUDED_ +#define HEIGHT_H_INCLUDED_ + /* Created by "tools/createGeoidGrid 1.0 int8_t" using GeographicLib utility GeoidEval with egm96-5. */ + +#include + #define GEOID_GRID_DEG 1.0 #define GEOID_SCALE 1.0 #define GEOID_ROW 181 @@ -205,3 +211,4 @@ static const int8_t geoid_delta[GEOID_COL* GEOID_ROW]= { /* 89.0 */ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, /* 90.0 */ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 }; +#endif // HEIGHT_H_INCLUDED_ diff --git a/magellan.h b/magellan.h index 69fa0e953..4b9208f5b 100644 --- a/magellan.h +++ b/magellan.h @@ -17,6 +17,12 @@ */ +#ifndef MAGELLAN_H_INCLUDED_ +#define MAGELLAN_H_INCLUDED_ + +#include +#include "defs.h" + /* * Table of "interesting" Magellan models. * Selfishly, if I haven't heard of it, it's not in the table. @@ -52,3 +58,5 @@ QString m330_cleanse(const char* istring); Waypoint* mag_trkparse(char* trkmsg); void mag_rteparse(char* rtemsg); + +#endif // MAGELLAN_H_INCLUDED_ diff --git a/navilink.h b/navilink.h index 05ef375bb..9f0cc5124 100644 --- a/navilink.h +++ b/navilink.h @@ -20,8 +20,8 @@ */ -#ifndef gpsbabel_navilink_h_included -#define gpsbabel_navilink_h_included +#ifndef NAVILINK_H_INCLUDED_ +#define NAVILINK_H_INCLUDED_ #include #include "defs.h" @@ -133,4 +133,4 @@ typedef struct __packed { #endif -#endif /* gpsbabel_navilink_h_included */ +#endif // NAVILINK_H_INCLUDED diff --git a/queue.h b/queue.h index 48771efbc..863d046a1 100644 --- a/queue.h +++ b/queue.h @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ +#ifndef QUEUE_H_INCLUDED_ +#define QUEUE_H_INCLUDED_ typedef struct queue { struct queue* next; @@ -58,3 +60,4 @@ void sortqueue(queue* qh, int (*cmp)(const queue*, const queue*)); (tmp) = QUEUE_NEXT(element), \ (element) != (listhead); \ (element) = (tmp)) +#endif // QUEUE_H_INCLUDED_ diff --git a/session.h b/session.h index f8b61624a..1a32385cb 100644 --- a/session.h +++ b/session.h @@ -19,8 +19,10 @@ */ -#ifndef SESSION_H -#define SESSION_H +#ifndef SESSION_H_INCLUDED_ +#define SESSION_H_INCLUDED_ + +#include "queue.h" typedef struct { queue Q; @@ -48,4 +50,4 @@ session_t* curr_session(void); int session_add_category(const char *name, const int id); */ -#endif +#endif // SESSION_H_INCLUDED_ diff --git a/xmlgeneric.h b/xmlgeneric.h index 487866d1d..52fd007db 100644 --- a/xmlgeneric.h +++ b/xmlgeneric.h @@ -19,6 +19,16 @@ */ +#ifndef XMLGENERIC_H_INCLUDED_ +#define XMLGENERIC_H_INCLUDED_ + +#include + +// Maybe the XmlGeneric string callback really shouldn't have a type +// of its own; this was a crutch during the move from char* to QString. +// It's "just" a search and replace to make it go away, but it might +// be convenient to overload some day. +typedef const QString& xg_string; typedef enum { @@ -40,10 +50,10 @@ extern const char* xhtml_entities; void xml_ignore_tags(const char** taglist); void xml_init(const QString& fname, xg_tag_mapping* tbl,const char* encoding); -void xml_init_offset(const char* fname, xg_tag_mapping* tbl, - const char* encoding, gbsize_t offset); void xml_read(void); void xml_readstring(const char* str); void xml_readprefixstring(const char* str); void xml_readunicode(const QString& str); void xml_deinit(void); + +#endif // XMLGENERIC_H_INCLUDED_ -- 2.30.2